package cn.anc.aonicardv.util;

/**
 * Created by yangdai on 2017/5/20.
 */

public class TimeFormatUtils {


    public static String formatTime(Long ms) {

        long hourMs = 3600000;
        long minMs = 60000;
        long secMs = 1000;

        Long hour = ms / hourMs;
        Long minute = (ms - hour * hourMs) / minMs;
        Long second = (ms - hour * hourMs - minute * minMs) / secMs;

        StringBuffer sb = new StringBuffer();
        if (hour > 0) {
            if (hour < 10)
                sb.append("0" + hour + ":");
            else
                sb.append(hour + ":");
        }
        if (minute < 10)
            sb.append("0" + minute + ":");
        else
            sb.append(minute + ":");
        if (second < 10)
            sb.append("0" + second);
        else
            sb.append(second);
        return sb.toString();
    }

    public static Long  formatEndTime(long StartTime,String time) {
        long hourMs = 3600000;
        long minMs = 60000;
        long secMs = 1000;
        long resultTime ;
        try{
            String[] mTime =time.split(":");
            if (mTime.length ==3){
                int mHTime = Integer.parseInt(mTime[0]);
                int mMTime = Integer.parseInt(mTime[1]);
                int mSTime = Integer.parseInt(mTime[2]);
                resultTime = StartTime +hourMs*mHTime+mMTime*minMs+mSTime*secMs;
            }else  if (mTime.length ==2){
                int mMTime = Integer.parseInt(mTime[0]);
                int mSTime = Integer.parseInt(mTime[1]);
                resultTime = StartTime +mMTime*minMs+mSTime*secMs;
            }else{
                int mSTime = Integer.parseInt(mTime[0]);
                resultTime = StartTime +mSTime*secMs;
            }

        }catch (Exception e){
           resultTime = 0;
        }
        return resultTime;
    }



}
